/**
 * Project hdmap
 * @author shengjialiang
 * @version v1.0
 */


#ifndef _IRENDEROBJECT_H
#define _IRENDEROBJECT_H

#include "map_common/Object.h"
#include "map_datarender/DataRenderConfig.h"
#include "map_dataset/IFeature.h"
#include "osg/Group"
#include <osgViewer/Viewer>
#include "OpenThreads/Mutex"
#include <osg/MatrixTransform>

namespace DataRender
{
    class IRenderObject;
    class MAP_DATARENDER_EXPORT CRenderNode : public osg::MatrixTransform
    {
    public:
        CRenderNode();

        virtual ~CRenderNode();

    public:
        IRenderObject* Owner;
    };

    class MAP_DATARENDER_EXPORT IRenderObject : public Common::CObject
    {
    public:

        IRenderObject(osg::ref_ptr<osg::Group> in_pParentNode);

        virtual ~IRenderObject();

        osg::ref_ptr<osg::Group> IRenderObject::getParentNode();

        osg::ref_ptr<CRenderNode> getRenderNode();

        virtual void setFeature(DataManager::IFeature* in_pFeature);

        virtual DataManager::IFeature* getFeature();

		virtual void setOwner(Common::CObject* in_pRefOwner);

		virtual Common::CObject* getOwner();

        virtual osg::Matrix getMatrix();

        virtual void setMatrix(const osg::Matrix& in_matrix);

        virtual osg::Matrix getAdjustMatrix();

        virtual void setAdjustMatrix(const osg::Matrix& in_adjustmatrix);

        virtual void setVisible(const bool& in_visible);

        virtual bool getVibible();

		virtual void setVisibleDistance(const double& in_visibleDistance);

		virtual double getVisibleDistance();

        virtual bool load() = 0;

        virtual bool render() = 0;

        virtual bool unload() = 0;

        virtual bool canRender(osg::Node* node, osg::NodeVisitor* nv, osgViewer::Viewer* viewer);

        virtual bool& getCanSelect();

        virtual osg::BoundingBox& getBox();

        virtual std::string getRenderType();

        virtual void setRenderType(const std::string& in_renderType);

    protected:

        void lock();

        void unlock();

    protected:
        DataManager::IFeature* mpRefFeature;
        osg::ref_ptr<osg::Group> mpRefParentNode;
        OpenThreads::Mutex mRenderMutex;
		Common::CObject* mpRefOwner;
        osg::ref_ptr<CRenderNode> mpRenderNode;
        osg::BoundingBox mBox;
        osg::Matrix mMatrix;
        osg::Matrix mAdjustmatrix;
        std::string mRenderType;
        bool mCanSelect;
        bool mVisible;
		double mVisibleDistance;
    };
}

#endif //_IRENDEROBJECT_H